package com.pine.app.module.security.oauth.provider.client.service.impl;

import com.pine.app.module.security.core.common.AuthConstant;
import com.pine.app.module.security.oauth.provider.client.ClientDetails;
import com.pine.app.module.security.oauth.provider.client.ClientDetailsService;
import com.pine.app.module.security.oauth.provider.client.service.ClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;

/**
 * @author xiaoyuan
 * @create 2020/3/13 9:15
 **/

public class DataBaseCacheClientDetailServiceImpl implements ClientDetailsService {


    private ClientService clientService;

    @Autowired
    public void setClientService(ClientService clientService) {
        this.clientService = clientService;
    }

    public DataBaseCacheClientDetailServiceImpl(){

    }




    public DataBaseCacheClientDetailServiceImpl(ClientService clientService){
        this.clientService = clientService;
    }


    public  static final String OAUTH_CLINET_DETAILS_CACHE = AuthConstant.CACHE_NAMESPACE+"CLIENT:";


    @Cacheable(value = OAUTH_CLINET_DETAILS_CACHE, key = "#clientId")
    @Override
    public ClientDetails loadClientDetail(String clientId) {
        return clientService.getByClientId(clientId);
    }
}
